package com.framework.service.core.controller;

import com.framework.common.controller.BaseController;
import com.framework.common.domain.R;
import com.framework.service.core.service.IThirdUserInfoService;
import com.framework.core.api.request.ThirdUserInfoReq;
import com.framework.core.api.response.ThirdUserInfoQueryRes;
import com.framework.core.api.response.ThirdUserInfoRes;
import com.framework.service.core.service.IThirdUserInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author zhoubb
 * @version V1.0
 * @Date 2020/4/14 0:17
 * @since JDK 1.8
 */
@RestController
@RequestMapping("/thirdUser")
@Api(value = "ThirdUserController", description = "第三方用户管理")
public class ThirdUserController extends BaseController {

    @Autowired
    private IThirdUserInfoService thirdUserInfoService;


    @ApiOperation(value = "新增第三方用户", httpMethod = "POST")
    @RequestMapping(value = "/registerThirdUser",method = RequestMethod.POST)
    @ResponseBody
    public R registerThirdUser(ThirdUserInfoReq thirdUserInfoReq) {
        ThirdUserInfoRes res = thirdUserInfoService.insertThirdUserInfo(thirdUserInfoReq);
        return R.ok(res.getCode(),res.getMsg());
    }

    @ApiOperation(value = "根据openId获取或者注册第三方用户信息", httpMethod = "POST")
    @PostMapping("/getOrRegThirdUserInfoByOpenId")
    @ResponseBody
    public ThirdUserInfoQueryRes getOrRegThirdUserInfoByOpenId(@RequestBody ThirdUserInfoReq thirdUserInfoReq) {
        return thirdUserInfoService.getOrRrgisterWxUserInfo(thirdUserInfoReq);
    }

    @ApiOperation(value = "根据openId获取第三方用户信息", httpMethod = "GET")
    @GetMapping("/getThirdUserInfoByOpenId")
    @ResponseBody
    public ThirdUserInfoQueryRes getThirdUserInfoByOpenId(@RequestParam String openId) {
        ThirdUserInfoReq thirdUserInfoReq = new ThirdUserInfoReq();
        thirdUserInfoReq.setOpenId(openId);
        return thirdUserInfoService.getThirdUserInfo(thirdUserInfoReq);
    }
}
